package com.bitinstitute.parkapp.animals.types;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.MediaController;
import android.widget.VideoView;

import com.bitinstitute.parkapp.R;

public class TypesVideoActivity extends Activity {

	// XML Video key
	static final String KEY_VIDEO = "video";

	MediaPlayer mediaPlayer = new MediaPlayer();
	VideoView videoView;
	ImageButton soundButton;

	@SuppressLint("NewApi")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		setContentView(R.layout.types_video);

		Intent in = getIntent();

		// Url from video-file
		final String video_url = in.getStringExtra(KEY_VIDEO);

		videoView = (VideoView) findViewById(R.id.video);
		MediaController mc = new MediaController(this);
		mc.setMediaPlayer(videoView);

		Uri video = Uri.parse(video_url);
		videoView.setMediaController(mc);
		videoView.setVideoURI(video);
		videoView.start();

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (mediaPlayer != null) {
			mediaPlayer.release();
			mediaPlayer = null;
		}

		if (videoView != null) {
			videoView.stopPlayback();
			videoView = null;
		}

	}

}
